// 预约页面逻辑
Page({
  data: {
    services: [
      { id: 1, name: "深层净肤", price: 298 },
      { id: 2, name: "深层补水", price: 358 },
      { id: 3, name: "敏肌修护", price: 428 },
      { id: 4, name: "美白提亮", price: 398 },
      { id: 5, name: "痘肌救星", price: 458 },
      { id: 6, name: "紧致抗衰", price: 528 }
    ],
    selectedServiceId: null,
    formData: {
      name: '',
      phone: '',
      date: '',
      time: '',
      remark: ''
    }
  },

  onLoad() {
    console.log('预约页面加载')
  },

  // 选择服务
  onServiceSelect(e) {
    const serviceId = e.currentTarget.dataset.id
    this.setData({
      selectedServiceId: serviceId
    })
  },

  // 表单输入处理
  onNameInput(e) {
    this.setData({
      'formData.name': e.detail.value
    })
  },

  onPhoneInput(e) {
    this.setData({
      'formData.phone': e.detail.value
    })
  },

  onDateChange(e) {
    this.setData({
      'formData.date': e.detail.value
    })
  },

  onTimeChange(e) {
    this.setData({
      'formData.time': e.detail.value
    })
  },

  onRemarkInput(e) {
    this.setData({
      'formData.remark': e.detail.value
    })
  },

  // 提交预约
  onSubmit() {
    const { formData, selectedServiceId } = this.data
    
    if (!selectedServiceId) {
      wx.showToast({
        title: '请选择服务项目',
        icon: 'none'
      })
      return
    }

    if (!formData.name || !formData.phone || !formData.date || !formData.time) {
      wx.showToast({
        title: '请填写完整信息',
        icon: 'none'
      })
      return
    }

    // 模拟提交成功
    wx.showToast({
      title: '预约成功',
      icon: 'success',
      duration: 2000,
      success: () => {
        setTimeout(() => {
          wx.navigateBack()
        }, 2000)
      }
    })
  }
})